/*
   Copyright (c) 2010-
   Winnem Consulting
   Kirkealleen 58
   3470 Slemmestad
   Norway


   All rights reserved.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
   IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
   PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.winnemconsulting.puremvccodegen.view.components.dbconfig
{
	import com.winnemconsulting.puremvccodegen.ApplicationFacade;
	import com.winnemconsulting.uicomponents.alert.ExtendedAlert;

	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

	public class DBSetupMediator extends Mediator implements IMediator
	{
		/**
		 * Name of this mediator
		 */
		public static const NAME:String="DBSetupMediator";

		public function DBSetupMediator(viewComponent:Object=null)
		{
			super(NAME, viewComponent);
		}


		/**
		 * Getting the view component
		 * @return viewComponent
		 */
		public function getViewComponent():Object
		{
			return super.viewComponent;
		}

		/**
		 * Casting viewcomponent to its original type
		 * @return DBConfig
		 */
		public function dbSetup():DBConfig
		{
			return super.viewComponent as DBConfig;
		}

		/**
		 * Setting viewComponent
		 * @param data the gui this mediator is connected to
		 */
		public function setViewComponent(data:Object):void
		{
			super.viewComponent=Object;
		}

		/**
		 * @inheritDoc
		 */
		override public function listNotificationInterests():Array
		{
			return [ApplicationFacade.DBSERVER_CONNECTED_FAIL, ApplicationFacade.DBSERVER_CONNECTED_OK];
		}

		/**
		 * @inheritDoc
		 */
		public function handleNotification(notification:INotification):void
		{
			switch (notification.getName())
			{
				case ApplicationFacade.DBSERVER_CONNECTED_FAIL:
					{
						ExtendedAlert.showExtended("Connection failed", "Error", null, null, null, ExtendedAlert.ICON_ERROR16);
						break;
					}
				case ApplicationFacade.DBSERVER_CONNECTED_OK:
					{
						ExtendedAlert.showExtended("Connection OK", "Info", null, null, null, ExtendedAlert.ICON_INFORMATION16);
					}
			}
		}

		/**
		 * @inheritDoc
		 */
		public function onRegister():void
		{
			//TODO: implement function
		}

		/**
		 * @inheritDoc
		 */
		public function onRemove():void
		{
			//TODO: implement function
		}
	}
}